
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "beamformer.h"

#define FRAME 160

int main(int argc, char *argv[])
{
    FILE *fidr = fopen(argv[1], "rb");
    fseek(fidr, 0, SEEK_END); int d2 = ftell(fidr);
    fseek(fidr, 0, SEEK_SET); int d1 = ftell(fidr);	
    int frames = (d2-d1)/sizeof(short)/FRAME/2; 
    printf("total frames = %d\n", frames); 
    FILE *fidw = fopen("aec.pcm", "wb");

    short xbuf[FRAME*2] = {0};
    short ybuf[FRAME] = {0};

    void *dual = create_beamformer(FRAME, 16000, 2);

    for (int n=0; n<frames; n++) {
        fread(xbuf, sizeof(short), FRAME*2, fidr);
        process_beamformer(dual, xbuf, ybuf);
        fwrite(ybuf, sizeof(short), FRAME, fidw);
    }

    destroy_beamformer(dual);
    fclose(fidr); fclose(fidw);
    return 0;
}